package cn.haoma.base.socket;

import android.util.SparseArray;

import java.lang.reflect.Field;
import java.nio.charset.Charset;

public class MsgProtocol {
    /**
     * 心跳
     */
    public final static byte CMD_HEART_BEAT = 2; //原样返回
    /**
     * 上线（客户端）
     */
    public final static byte CMD_ONLINE = 1; //CMD返回为5, content:sucuccess或者fail

    public final static byte CMD_CONFIRM = 5;  //上线返回专用！服务器返回消息CMD改成5;


    public final static byte CMD_UPDATE_LOCATION = 3; //位置更新，无需返回


    public final static byte CMD_OFFLINE = 4; //下线指令，无需返回

    public final static byte CMD_ORDER = 6; //下线指令，无需返回

    public final static byte CMD_MIDPOINT = 7; //中间点指令，无需返回

    public final static byte CMD_FINISH_MIDPOINT = 8; //结束中间点指令，无需返回
    public final static byte CMD_SOCKET_CLOSE = 9; //结束中间点指令，无需返回
    public final static byte CMD_SOCKET_EXCEPTION = 10; //服务器处理出错
    public static Charset CHARSET = Charset.forName("UTF-8");
    private static SparseArray<String> map = new SparseArray<>();

    static {
        Field[] fields = MsgProtocol.class.getFields();
        Object o = new MsgProtocol();
        try {
            for (Field field : fields) {
                String name = field.getName();
                if (name.startsWith("CMD_")) {
                    byte value = field.getByte(o);
                    map.put(value, name);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static String getCmdName(byte cmd) {
        return map.get(cmd);
    }

}
